package com.qtu.order_service.rabbitmq;

import com.qtu.entity.BmSpecification;
import com.qtu.order_service.mapper.BmGoodMapper;

import com.qtu.order_service.mapper.BmInordergoodslistMapper;
import com.qtu.order_service.mapper.BmSpecificationMapper;
import com.qtu.order_service.openfeign.RedisFeignClient;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author CaiYinWei
 * @create 2020-07-14 14:19
 */
@Service
public class RabbitmqServer {
    //redis中购物车对应的key前缀
    private String REDIS_CART_KEY = "CART_KEY";

    //redis购物车商品项对应的key前缀
    private String REDIS_CART_ITEM_KEY = "CART_ITEM_KEY";
    @Autowired
    private RedisFeignClient redisFeignClient;

    @Autowired
    private BmGoodMapper bmGoodMapper;

    @Autowired
    private BmSpecificationMapper bmSpecificationMapper;

    @Autowired
    private com.qtu.order_service.mapper.BmInordergoodslistMapper BmInordergoodslistMapper;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RabbitListener(queues = {"order.commit"})
    public void receiveOrder(BmSpecification bmSpecification){
//        rabbitTemplate.receiveAndConvert("order.commit");
        BmSpecification bmSpecification1 = bmSpecificationMapper.selectById(bmSpecification.getId());
        bmSpecification1.setStock(bmSpecification.getStock());
        int i = bmSpecificationMapper.updateById(bmSpecification1);
        System.err.println("--------------"+i);
    }

//        @RabbitListener(queues = {"order.commit"})
//        public void receiveOrder(BmSpecification bmSpecification){
//            System.err.println("+++++++++++"+bmSpecification);
//        }

    @RabbitListener(queues = {"order.direct.lazy"})
    public void receiveOrderLazy(String orderId){
        BmInordergoodslistMapper.deleteById(orderId);
        BmSpecification bmSpecification = new BmSpecification();

//        bmSpecificationMapper.updateById();
    }

    @RabbitListener(queues = {"order.direct.lazy"})
    public void receiveOrder2(BmSpecification bmSpecification){
        bmSpecificationMapper.updateById(bmSpecification);
    }

}
